package com.servlet;

import com.dao.CardtypeDao;
import com.dao.Impl.CardtypeDaoImpl;
import com.util.MyUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(value = "/cardTypeServlet/*")
public class CardTypeServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String url=request.getRequestURI();
        String method=url.substring(url.lastIndexOf("/")+1);
        String target=null;
        switch (method){
            case "findAllCardType":
                target=findAllCardType(request,response);
                break;
            default:
                break;
        }
        if (target!=null){
            request.getRequestDispatcher(target).forward(request,response);
        }
    }

    /**
     * 查询会员等级
     * @param request
     * @param response
     * @return
     * @throws ServletException
     * @throws IOException
     */
    protected String findAllCardType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        CardtypeDao dao=new CardtypeDaoImpl();
        List<Map> allCardType = dao.findAllCardType();
        MyUtil.jsonWriter(response,allCardType);
        return null;
    }
}
